package com.molichuxing.gateway.bff.basic.services.impl;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.gateway.bff.basic.convertor.Convert;
import com.molichuxing.gateway.bff.basic.entity.response.VehicleMakeVo;
import com.molichuxing.gateway.bff.basic.entity.response.VehicleModleMakeInfoVo;
import com.molichuxing.gateway.bff.basic.entity.response.VehicleModlemakeVo;
import com.molichuxing.gateway.bff.basic.services.VehicleBffService;
import com.molichuxing.gateway.bff.car.entity.response.MaintenanceConfigVo;
import com.molichuxing.services.business.dto.response.VehicleInfoBizDto;
import com.molichuxing.services.business.service.VehicleBizService;
import com.molichuxing.services.infrastructure.service.MaintenanceConfigService;
import com.molichuxing.services.infrastructure.service.VehicleMakeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("vehicleBffService")
public class VehicleBffServiceImpl implements VehicleBffService {
    private static final Logger logger = LoggerFactory.getLogger(VehicleBffServiceImpl.class);

    @Resource
    private VehicleBizService vehicleBizService;

    @Resource
    private VehicleMakeService vehicleMakeService;

    @Resource
    private MaintenanceConfigService maintenanceConfigService;

    @Override
    public List<VehicleModlemakeVo> getVehicleModlemakeBizDto() {
        return Convert.toVehicleModlemakeVo(vehicleBizService.getVehicleModlemakeBizDto());
    }

    @Override
    public List<VehicleModlemakeVo> getMaintenanceVehicleModlemakeBizDto() {
        List<Integer> vehicleIdList = maintenanceConfigService.getVehicleIdList();
        return Convert.toVehicleModlemakeVo(vehicleBizService.getMaintenanceVehicleModlemakeBizDto(vehicleIdList));
    }

    @Override
    public List<VehicleMakeVo> getModelMakeList(Integer isMainMake) {
        return Convert.toVehicleMakeVo(vehicleMakeService.getVehicleMakeDto(isMainMake));
    }

    @Override
    public String getVehicleName(Integer vehicleId) {
        return vehicleBizService.getVehicleName(vehicleId);
    }

    /**
     * 车型分页
     *
     * @param map
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Paged<VehicleModleMakeInfoVo> getVehiclePage(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        Paged<VehicleInfoBizDto> vehiclePage = vehicleBizService.getVehiclePage(map, pageNum, pageSize);
        List<VehicleInfoBizDto> list = vehiclePage.getList();
        if (null == list || list.size() < 1) {
            return new Paged<VehicleModleMakeInfoVo>();
        }

        List<VehicleModleMakeInfoVo> voList = Convert.toVehicleModleMakeInfoVoList(list);
        return new Paged<VehicleModleMakeInfoVo>(voList, vehiclePage.getTotal(), pageSize);
    }

    /**
     * 查询车型
     *
     * @param id
     * @return
     */
    @Override
    public VehicleModleMakeInfoVo getVehicleInfo(Integer id) {
        VehicleInfoBizDto vehicleInfo = vehicleBizService.getVehicleInfo(id);
        if (null == vehicleInfo) {
            return null;
        }

        return Convert.toVehicleModleMakeInfoVo(vehicleInfo);
    }

}
